const state = () => ({
  //商品页
  GOOD_ITEM_CELL_COUNT: 3, //商品列表每行显示的个数
  GOOD_LEFT_MENU_CLICK: "", //商品列表的Tree类型选择
  GOOD_LEFT_MENU_TITLE: "", //商品列表的Tree类型选择的名字
  GOOD_LEFT_MENU_Filter: {
    brand_list: [],
    printable_surface: [],
  }, //商品列表的过滤器
  GOOD_LIST_SORT: 1,
  GOOD_LIST_PAGE_TO_TOP: false, //商品列表滚动至100px高度
  GOOD_ONE_PRINT_PRICE: 100, //打印面单面价格
  Product_Classify: [],
});
const getters = {
  user: (state) => state.user,
  GOOD_LEFT_MENU_CLICK: (state) => state.GOOD_LEFT_MENU_CLICK,
  GOOD_LEFT_MENU_Filter: (state) => state.GOOD_LEFT_MENU_Filter,
  GOOD_LIST_PAGE_TO_TOP: (state) => state.GOOD_LIST_PAGE_TO_TOP,
  getProductClass: (state) => state.Product_Classify,
};
const mutations = {
  SET_PRODUCT_CLASSIFY(state, { payload }) {
    if (payload) {
      state.Product_Classify = payload;
    } else {
      state.Product_Classify = [];
    }
  },
  SET_USER(state, { user }) {
    if (user) {
      state.user = user;
    } else {
      state.user = {};
    }
  },
  INIT_GOOD_LEFT_CHECK(state, { num }) {
    if (num) {
      state.GOOD_LEFT_MENU_CLICK = num;
    } else {
      state.GOOD_LEFT_MENU_CLICK = 0;
    }
  },
  SET_GOOD_LEFT_MENU_Filter(state, { data }) {
    if (data) {
      state.GOOD_LEFT_MENU_Filter = data;
    } else {
      state.GOOD_LEFT_MENU_Filter = {
        brand_list: [],
        printable_surface: [],
      };
    }
  },
  INIT_GOOD_LEFT_MENU_Filter(state) {
    state.GOOD_LEFT_MENU_Filter = {
      brand_list: [],
      printable_surface: [],
    };
  },
  SET_GOOD_LIST_PAGE_TO_TOP(state, { bol }) {
    state.GOOD_LIST_PAGE_TO_TOP = bol;
  },
  SET_USER_TOKEN(state, { data }) {
    state.USER_TOKEN = data;
  },
  REMOVE_USER_TOKEN(state) {
    state.USER_TOKEN = "";
  },
  SET_USER_INFO(state, { data }) {
    state.USER_INFO = data;
  },
};
const actions = {
  setProductClassify({ commit }, payload) {
    commit("SET_PRODUCT_CLASSIFY", { payload });
  },
  setUser({ commit }, user) {
    commit("SET_USER", { user });
  },
  setGoodLeftCheck({ commit }, num) {
    commit("INIT_GOOD_LEFT_CHECK", { num });
  },
  setGoodLeftFilter({ commit }, data) {
    commit("SET_GOOD_LEFT_MENU_Filter", { data });
  },
  initGoodLeftFilter({ commit }) {
    commit("INIT_GOOD_LEFT_MENU_Filter");
  },
  setGoodListPageToToP({ commit }, bol) {
    commit("SET_GOOD_LIST_PAGE_TO_TOP", { bol });
  },
  setUserToken({ commit }, data) {
    commit("SET_USER_TOKEN", { data });
  },
  removeUserToken({ commit }) {
    commit("REMOVE_USER_TOKEN");
  },
  setUserInfo({ commit }, data) {
    commit("SET_USER_INFO", { data });
  },
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions,
};
